﻿using Core.DataAccess.Model;
using Core.Framework;
using Grain.State.BaseModule.StorgeStates;
using iTool.ClusterComponent;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Grain.Interfaces
{
    public interface IChannelService : iToolServiceWithStringKey
    {
        Task ModifyMessageStatus(DBNotifyMessage message);

        /// <summary>
        /// 订阅
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        Task Subscribe(string topic);

        /// <summary>
        /// 取消订阅
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        Task UnSubscribe(string topic);

        /// <summary>
        /// 获取订阅的Topics
        /// </summary>
        /// <returns></returns>
        Task<List<string>> GetSubscribes();

        /// <summary>
        /// 设置渠道信息
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        Task SetChannelInfo(string parameter);

        /// <summary>
        /// 设置渠道Session
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        Task SetChannelSesstion(string parameter);

        /// <summary>
        /// 获取渠道信息
        /// </summary>
        /// <returns></returns>
        Task<string> GetChannelInfo();

        /// <summary>
        /// 获取Session信息
        /// </summary>
        /// <returns></returns>
        Task<string> GetChannelSesstion();

        /// <summary>
        /// 接收消息事件
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="message"></param>
        /// <param name="sendOfChannel">发送消息的Channel</param>
        /// <returns></returns>
        Task ReceiveMessageEvent(string message, string sendChannel, string sendParameter);

        /// <summary>
        /// 发送消息事件
        /// </summary>
        /// <param name="message"></param>
        /// <param name="receiveChannel"></param>
        /// <param name="receiveParameter"></param>
        /// <returns></returns>
        Task SendMessageEvent(string message, string receiveChannel, string receiveParameter);

        /// <summary>
        /// 消息已读
        /// </summary>
        /// <param name="receiveChannel"></param>
        /// <returns></returns>
        Task ReaderChannel(string receiveChannel);

        /// <summary>
        /// 是否在指定channel
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        Task<bool> IsInChannel(string channel);

        /// <summary>
        /// 进入某会话
        /// </summary>
        /// <param name="channel">channel</param>
        /// <returns></returns>
        Task<KeyValuePair<bool, string>> IntoChannel(string channel);

        /// <summary>
        /// 退出某会话
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        Task OutChannel(string channel);

        /// <summary>
        /// 删除指定渠道信息
        /// </summary>
        /// <param name="sendOfChannel"></param>
        /// <returns></returns>
        Task RemoveSesstionByChannel(string sendOfChannel);

        /// <summary>
        /// 上线
        /// </summary>
        /// <param name="service">服务器地址</param>
        /// <param name="room">当前所在会话</param>
        /// <returns></returns>
        Task GoOnline(string service, string room = null);

        Task<bool> IsOnline();

        /// <summary>
        /// 下线
        /// </summary>
        /// <param name="service">服务器地址</param>
        /// <returns></returns>
        Task Offline(string service);

        /// <summary>
        /// 获取会话列表
        /// </summary>
        /// <returns></returns>
        Task<Dictionary<string, Sesstion>> GetSesstion(DateTime? lastDateTime);

        /// <summary>
        /// 获取消息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="reciveChannel"></param>
        /// <param name="minDateTime"></param>
        /// <returns></returns>
        Task<Pagination> GetMessage(Pagination pagination, string reciveChannel, DateTime minDateTime);

        /// <summary>
        /// 获取区间消息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="reciveChannel"></param>
        /// <param name="minDateTime"></param>
        /// <param name="minHistoryDateTime"></param>
        /// <returns></returns>
        Task<Pagination> GetMessage(Pagination pagination, string reciveChannel, DateTime minDateTime, DateTime minHistoryDateTime);

        /// <summary>
        /// 获取消息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="reciveChannel"></param>
        /// <param name="minDateTime"></param>
        /// <returns></returns>
        Task<Pagination> GetMessageOfGroup(Pagination pagination, string reciveChannel, DateTime minDateTime);

        /// <summary>
        /// 获取区间消息
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="reciveChannel"></param>
        /// <param name="minDateTime"></param>
        /// <param name="minHistoryDateTime"></param>
        /// <returns></returns>
        Task<Pagination> GetMessageOfGroup(Pagination pagination, string reciveChannel, DateTime minDateTime, DateTime minHistoryDateTime);
    }
}
